### Set Directory
try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path)))
rm(list=ls())

### Load Package
library(stargazer)
library(dplyr)

### Load Data
data = read.csv('replication tsc.csv') %>%
  # modify only for interpretation purpose
  mutate(tphysintrev = tphysintrev+8) %>%
  mutate(physintrev = physintrev+8) %>%
  mutate(lphysintrev = lphysintrev+8)

### First Stage (without control)

## All Sanctions
m12 = lm(v2juncind.rev~v2juncind.rev.lag+sanction, data=data)
m13 = lm(v2x_corr~v2x_corr.lag+sanction, data=data)
m14 = lm(v2mecenefm.rev~v2mecenefm.rev.lag+sanction, data=data)

## Human rights/Non-human-rights Sanctions
m15 = lm(v2juncind.rev~v2juncind.rev.lag+hrdummy+nonhrdummy, data=data)
m16 = lm(v2x_corr~v2x_corr.lag+hrdummy+nonhrdummy, data=data)
m17 = lm(v2mecenefm.rev~v2mecenefm.rev.lag+hrdummy+nonhrdummy, data=data)

# Table OA6
stargazer(m12,m13,m14,m15,m16,m17,type='text',
          keep.stat=c('n','rsq','f'))

### First Stage (with control)

## All Sanctions
m18 = lm(v2juncind.rev~v2juncind.rev.lag+sanction+polconiii+yr_sch_sec+open.log, data=data)
m19 = lm(v2x_corr~v2x_corr.lag+sanction+polconiii+yr_sch_sec+open.log, data=data)
m20 = lm(v2mecenefm.rev~v2mecenefm.rev.lag+sanction+polconiii+yr_sch_sec+open.log, data=data)

## Human rights/Non-human-rights Sanctions
m21 = lm(v2juncind.rev~v2juncind.rev.lag+hrdummy+nonhrdummy+polconiii+yr_sch_sec+open.log, data=data)
m22 = lm(v2x_corr~v2x_corr.lag+hrdummy+nonhrdummy+polconiii+yr_sch_sec+open.log, data=data)
m23 = lm(v2mecenefm.rev~v2mecenefm.rev.lag+hrdummy+nonhrdummy+polconiii+yr_sch_sec+open.log, data=data)

# Table OA7
stargazer(m18,m19,m20,m21,m22,m23,type='text',
          keep.stat=c('n','rsq','f'))

### Second Stage

## All Sanctions
m24 = lm(tphysintrev~+physintrev+sanction, data=data)
m25 = lm(tphysintrev~physintrev+sanction+v2juncind.rev+v2x_corr+v2mecenefm.rev, data=data)
m26= lm(tphysintrev~physintrev+sanction+v2juncind.rev+v2x_corr+v2mecenefm.rev+gdppclog+polity2+civilwar+interwar, data=data)

## Human rights/Non-human-rights Sanctions
m27 = lm(tphysintrev~+physintrev+hrdummy+nonhrdummy, data=data)
m28 = lm(tphysintrev~physintrev+hrdummy+nonhrdummy+v2juncind.rev+v2x_corr+v2mecenefm.rev, data=data)
m29= lm(tphysintrev~physintrev+hrdummy+nonhrdummy+v2juncind.rev+v2x_corr+v2mecenefm.rev+gdppclog+polity2+civilwar+interwar, data=data)

# Table OA8
stargazer(m24,m25,m26,m27,m28,m29,type='text',
          keep.stat=c('n','rsq','f'))

### Summary Statistics

# Table OA5
stargazer(as.data.frame(data %>%
                          select(physintrev,
                                 v2juncind.rev,
                                 v2x_corr,
                                 v2mecenefm.rev,
                                 sanction,
                                 hrdummy,
                                 nonhrdummy,
                                 polconiii,
                                 yr_sch_sec,
                                 open.log,
                                 gdppclog,
                                 polity2,
                                 civilwar,
                                 interwar)),
          type='text')
